package com.kdgc.power.business.controller;

import com.kdgc.power.business.entity.ComDictCat;
import com.kdgc.power.business.service.ComDictCatService;
import com.kdgc.power.fw.bean.JsonMsg;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("ComDictCat")
public class ComCDictCatController {
    @Autowired
    private ComDictCatService comDictCatService;

    @ResponseBody
    @RequestMapping("page")
    public Object page(HttpServletRequest request, int page, int rows) {
        return comDictCatService.getPage( "comDictCat.select", null, page, rows);
    }

    @ResponseBody
    @RequestMapping("findById")
    public ComDictCat findById(Integer id) {
        return comDictCatService.getEntity(id);
    }

    @ResponseBody
    @RequestMapping("save")
    public JsonMsg save(ComDictCat comDictCat) {
        boolean success = comDictCatService.saveWithDict(comDictCat);
        return new JsonMsg(success);
    }

    @ResponseBody
    @RequestMapping("deleteById")
    public JsonMsg deleteById(Integer id) {
        int rows = comDictCatService.removeById(id);
        return new JsonMsg(rows == 1);
    }
}